//============================================================================
// Name        : AnnoyingAnacodnas.cpp
// Author      : NoName Team
// Version     :
// Copyright   : Yep
// Description : Just a Hello World!
//============================================================================

#include <iostream>
#include <complex> // Temporarily
#include "ether.h"
using namespace std;

// Main menu
void info() {
	cout<<"Options :"<<endl;
	cout<<"1 - Load map (formats : pbm, pgm, ppm, dat)"<<endl;
	cout<<"2 - Load robots"<<endl;
	cout<<"3 - Load log"<<endl;

	cout<<"s - Show map"<<endl;
	cout<<"b - Setting boundaries"<<endl;
	cout<<"d - d is for Dziergwa, that's good enough for me!" << endl;
	cout<<"r - Run simulation"<<endl;
	cout<<"q - Quit"<<endl<<endl;
}

// Wonderful and amazing text animated intro (polish edition)!
void intro()
{
	cout<<"Welcome in :"<<endl<<endl;
	cout<<"AAA N   N N   N OOO Y Y I N   N GGGG   AAA N   N AAA CCC OOO DDD ";
	cout<<"N   N AAA SSS"<<endl;
	cout<<"A A NN  N NN  N O O YYY I NN  N G      A A NN  N A A C   O O D D ";
	cout<<"NN  N A A S  "<<endl;
	cout<<"AAA N N N N N N O O  Y  I N N N G GG   AAA N N N AAA C   O O D D ";
	cout<<"N N N AAA SSS"<<endl;
	cout<<"A A N  NN N  NN O O  Y  I N  NN G  G   A A N  NN A A C   O O D D ";
	cout<<"N  NN A A   S"<<endl;
	cout<<"A A N   N N   N OOO  Y  I N   N GGGG   A A N   N A A CCC OOO DDD ";
	cout<<"N   N A A SSS"<<endl;

	cout<<endl<<"                            -LOL, Corvus frugilegus,";
    cout<<endl<<"                            -WTF is ''Anacodnas'' ??";
    cout<<endl<<"                            -Dziergwie wali spod pach"<<endl;
    cout<<endl<<"                            -Wcale nie, za to Marian to dalej pa�a!"<<endl;
}


// Eclipse SVN test
int main() {
	ether 		Jungle;
	fstream 	FileMap;
	fstream 	FileRobots;
	fstream 	FileLog;

	char c;               // char for switching options
	char f_name [FILE_L]; // name of the file

	Jungle.setlogOnNull();

	intro();
	info();
	cout<<"(? - info) Your choice : ";
	cin >> c;


	while(c!='q')
	{
		switch( c )
		{
			case '1' :
				cout<<"(Example - 1.pbm, 2.pgm, 3.ppm)\nEnter map file name:";
				cin >> f_name;
				cout << endl;
				FileMap.open (f_name, fstream::in );
				if(FileMap.good()) {
					cout <<"Opening file "<<f_name;
					Jungle.loadMap( FileMap );
					FileMap.close();
				}
				else cerr << "No file !"<<endl;
				break;

			case '2' :
				cout << "(Example - robots.dat)"<< "Enter robot file name:";
				cin >> f_name;
				cout << endl;
				FileRobots.open (f_name, fstream::in );
				if(FileRobots.good()) {
					cout <<"Loading robots file "<<f_name;
					Jungle.loadRobots( FileRobots );
					FileRobots.close();
				}
				else cerr << "No file !"<<endl;
				break;

			case '3' :
				//cout << "(Przykladowe pliki log.dat)"<<endl;
				cout << "Enter log file name : ";
				cin >> f_name;
				cout << endl;
				FileLog.open (f_name, fstream::in | fstream::out | fstream::app );
				if(FileLog.good()) {
					cout <<"Opening log "<<f_name;
					Jungle.loadLog( FileLog );
				}
				else cerr << "No file !"<<endl;
				break;

			case 's' :
				Jungle.showMap();
				break;
			case 'm' :
				FileMap.open ("1.pbm", fstream::in );
				if(FileMap.good()) {
					cout <<"Opening file "<<f_name;
					Jungle.loadMap( FileMap );
					FileMap.close();
				}
				else cerr << "No file !"<<endl;

				FileRobots.open ("2.dat", fstream::in );
				if(FileRobots.good()) {
					cout <<"Loading robots file "<<f_name;
					Jungle.loadRobots( FileRobots );
					FileRobots.close();
				}
				else cerr << "No file !"<<endl;

				FileLog.open ("log", fstream::in | fstream::out | fstream::app );
				if(FileLog.good()) {
					cout <<"Opening log "<<f_name;
					Jungle.loadLog( FileLog );
				}
				else cerr << "No file !"<<endl;

				Jungle.showMap();
				break;
			case 'b' :
				Jungle.setMaxTime( 1000 );
				break;

			case 'r' :
				Jungle.runSimulation(Jungle.getCurTime()+50);
				break;

			case '?' :
				info();
				break;

			case 'q' :
				break;

			case 'd' :
				double time=2;

				complex<double> Start;
				complex<double> End;
				Start = complex<int>(3,1);
				End = complex<int>(5,8);
				robot 	TinkyWinky(time, Start, End, Start, End);
				TinkyWinky.loadMap(Jungle.returnMap(),Jungle.returnMapSize());
				TinkyWinky.calculateTrack(Start,End);
				TinkyWinky.showRobotMap();

				break;
		}

		cout<<endl<<"(? - info) Your choice : ";
		cin >>c;
		cout<<endl;
	}

    cout<<"See you soon !" << endl;

    if(FileLog.good()) {
    	FileLog.close();
    }

	return 0;
}
